package com.meadvc.ssmdemo.controller;

import com.alibaba.fastjson.JSONObject;
import com.meadvc.ssmdemo.service.ContactService;
import com.meadvc.ssmdemo.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: ssm-demo
 * @description: 联系人控制类
 * @author: meadvc
 * @create: 2020-06-15 21:51
 **/
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService service;

    /**
     * 查询供应商列表
     */
    @GetMapping("/listSuppplier")
    @CrossOrigin
    public JSONObject listSuppplier(HttpServletRequest request) {
        int pagenum = Integer.parseInt(request.getParameter("pagenum"));
        int pagesize = Integer.parseInt(request.getParameter("pagesize"));
        //System.out.println(query+"--"+pagenum+"--"+pagesize);
        return service.listSuppplier(pagenum,pagesize);
    }

    /**
     * 添加供应商
     * @param requestJson
     * @return
     */
    @PostMapping("addSupplier")
    @CrossOrigin
    public JSONObject addSupplier(@RequestBody JSONObject requestJson) {
        return service.addSupplier(requestJson);
    }

    /**
     * 根据id获取供应商
     * @param request
     * @return
     */
    @GetMapping("/getSupplier")
    @CrossOrigin
    public JSONObject getSupplier(HttpServletRequest request) {
        int sid = Integer.parseInt(request.getParameter("sid"));
        return service.getSupplier(sid);
    }

    /**
     * 修改供应商
     * @param requestJson
     * @return
     */
    @PostMapping("updateSupplier")
    @CrossOrigin
    public JSONObject updateSupplier(@RequestBody JSONObject requestJson) {
        return service.updateSupplier(requestJson);
    }


    @PostMapping("deleteSupplier")
    @CrossOrigin
    public JSONObject deleteSupplier(@RequestBody JSONObject requestJson) {
        return service.deleteSupplier(requestJson);
    }



}
